Skip to content

Implement support for become and explicit tail call codegen for the LLVM backend #144232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

xacrimon
Copy link

@xacrimon xacrimon commented Jul 20, 2025

This PR implements codegen of explicit tail calls via become in rustc_codegen_ssa and support within the LLVM backend. Completes a task on (#112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use become on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged.

During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available here.

@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 20, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@xacrimon xacrimon force-pushed the explicit-tail-call branch from 6a6d3c2 to f912c90 Compare July 20, 2025 22:49
@rust-log-analyzer

This comment has been minimized.

@xacrimon xacrimon force-pushed the explicit-tail-call branch from f912c90 to 42c719e Compare July 20, 2025 23:02
@xacrimon xacrimon force-pushed the explicit-tail-call branch from b36cf15 to ac87434 Compare July 20, 2025 23:10
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xacrimon xacrimon force-pushed the explicit-tail-call branch from 138b2a7 to 3fac279 Compare July 21, 2025 00:14
@rust-log-analyzer

This comment has been minimized.

@jeffparsons
Copy link
Contributor

I suspect there is quite a bit of bikeshedding on how we should go about implementing this for WASM

I thought LLVM already supported the Wasm tail-call instructions — what's the missing piece that needs bikeshedding?

@oli-obk
Copy link
Contributor

oli-obk commented Jul 21, 2025

@rustbot author

it seems a tailcall test is still hitting a stack overflow, do you know why?

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 21, 2025
@xacrimon
Copy link
Author

xacrimon commented Jul 21, 2025

@rustbot author

it seems a tailcall test is still hitting a stack overflow, do you know why?

This was me mistakenly marking the rest @run-fail instead of @run-crash, that was intentional and it has now been fixed. That one is marked no-tce and doesn't use become. There is another one called tce instead of no-tce which uses become and is set to @run-pass.

@xacrimon
Copy link
Author

I suspect there is quite a bit of bikeshedding on how we should go about implementing this for WASM

I thought LLVM already supported the Wasm tail-call instructions — what's the missing piece that needs bikeshedding?

Ah, my knowledge is outdated then. I've edited my comment, though point still stands for backends that aren't llvm/gcc.

@xacrimon
Copy link
Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 21, 2025
@xacrimon xacrimon requested review from bjorn3 and tmiasko July 21, 2025 18:37
@xacrimon
Copy link
Author

@WaffleLapkin I'm going to go ahead and guess this is something you want to have a look at.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 22, 2025

@bors r+

Thanks! Glad we finally support it!

@bors
Copy link
Collaborator

bors commented Jul 22, 2025

📌 Commit ecf34e1 has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 22, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2025
…-obk

Implement support for `become` and explicit tail call codegen for the LLVM backend

This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (rust-lang#112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged.

During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 22, 2025
…-obk

Implement support for `become` and explicit tail call codegen for the LLVM backend

This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (rust-lang#112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged.

During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants